<?php

class BaseHomeAction extends Action {

	protected $uid;
	protected $sid;
	public $school;
	protected $User;
	protected $profile;
	protected $messageCount;
	protected $noticeCount;

	public function _initialize() {
		$this->uid = Session::get("user_id");
		//若有指定学校
		if ($_GET["school_abbr"]) {
			$this->school = get_shcool_info(array("school_abbr" => strtolower($_GET["school_abbr"])));
			return;
		}
		//若未指定学校，则查询所在学校
		if ((int) Session::get("school_id") > 0) {
			$this->school = get_shcool_info(Session::get("school_id"));
		}
	}

	public function init() {
		if (!empty($this->uid)) {
			$this->User = D('User')->where("user_id=" . $this->uid);
			//获取用户基本信息
			$this->profile = $this->User->relation('school')->cache("user_" . $this->uid)->find();
			//获取未读私信
			$this->messageCount = D('Message')->cache("message_new_" . $this->uid)->where("(user_id=" . $this->uid . " and status=0) or (from_id=" . $this->uid . " and from_status=0)")->count();
			//获取未读提醒
			$this->noticeCount = D('Notice')->cache("notice_new_" . $this->uid)->where("user_id=" . $this->uid . " and status=0")->count();

			$this->assign('profile', $this->profile);
			$this->assign('messageCount', $this->messageCount);
			$this->assign('noticeCount', $this->noticeCount);
		}
	}

}

?>
